﻿using System;

class Task3
{
    static void Main()
    {
        //Bulls and Cows
        // 6 / 100
        checked
        {
            int secretNumber = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());

            int firstNumber = secretNumber / 1000;
            int secondNumber = (secretNumber / 100) % 10;
            int thirdNumber = (secretNumber / 10) % 10;
            int fourthNumber = secretNumber % 10;

            int combinations = (int)Math.Pow(2, b); // -1

            if (b == 4)
            {
                Console.WriteLine(secretNumber);
            }
            else if (b == 3 && c == 0)
            {
                for (int i = 1; i <= 9; i++)
                {
                    Console.Write("{0}{1}{2}{3} ", firstNumber, secondNumber, thirdNumber, i);
                    Console.Write("{0}{1}{2}{3} ", i, firstNumber, secondNumber, thirdNumber);
                    Console.Write("{0}{1}{2}{3} ", firstNumber, secondNumber, i, fourthNumber);
                    Console.Write("{0}{1}{2}{3} ", firstNumber, i, thirdNumber, fourthNumber);
                }
            }
            else if (b == 3 && c == 1)
            {
                Console.Write("{0}{1}{2}{3} ", firstNumber, secondNumber, thirdNumber, c);
                Console.Write("{0}{1}{2}{3} ", c, firstNumber, secondNumber, thirdNumber);
                Console.Write("{0}{1}{2}{3} ", firstNumber, secondNumber, c, fourthNumber);
                Console.Write("{0}{1}{2}{3} ", firstNumber, c, thirdNumber, fourthNumber);
            }

        }
        



    }
}

